//
// Created by user on 2022/3/7.
//
#include <vector>
#include <algorithm>
using namespace std;
int longestMountain(vector<int>& arr) {
    int ans =0;
    int left =0;
    int n = arr.size();
    while (left+2<arr.size()){
        int right = left+1;//每次从left+1开始
        if(arr[left]<arr[right]){
            //找到最高点
            while (right+1<n && arr[right]<arr[right+1]){
                right++;
            }
            if(right+1<n &&arr[right]>arr[right+1]){
                //找最低点
                while (right+1<n && arr[right]>arr[right+1]){
                    right++;
                }
                ans = max(ans, right-left+1);
            }else{
                //arr[right]=arr[right+1]
                right++;
            }
        }
        left = right;
    }
    return ans;
}